// pages/rechargeRecord/rechargeRecord.js
var that,
  api = new (require('../../utils/api.js')),
  app = getApp(),
  util = new (require('../../utils/util.js'));
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list:[
    ],
    page:1,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    that=this;
    that.getdata();
  },
  getdata(){
    let {list,page}=that.data
    let {corpInvoiceTag} = app.logininfo
    that.setData({corpInvoiceTag})
    api.orderrecord(page,res=>{
      if(res.data.code==0){
        let {nextPage,orderArr}=res.data.entity.data
        if(orderArr.length>0){
          orderArr.forEach(x=>{
            x.date=util.formatTime(new Date(x.addTime*1000))
            list.push(x)
          })
        }
        that.setData({list,nextPage})
      }
    })
    // list.forEach(x=>{
    //   x['newprice']=parseInt(x.price/100)
    //   x['newrecharge']=parseInt(x.recharge/100)
    //   x['save']=parseInt((x.recharge-x.price)/100)
    // })
    that.setData({list})
  },
  toinvoice(){
    wx.navigateTo({
      url: '../drawabill/drawabill',
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    let {page,nextPage}=that.data
    if(nextPage==1){
      that.setData({page:page+1},()=>{
        that.getdata()
      })
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})